from django.template import Library

register = Library()

@register.filter
def escape_amp(value):
    #replaces &amp; with & - use for hardcoded html chars (&#353;)
    return str(value).replace("&amp;", "&")

@register.filter
def beautify_date(value):
    #used on the main page to show those super beautiful dates for each day
    return value.strftime("%A, %d. %B %Y").capitalize().decode('latin2')
    
@register.filter
def safe_email(value):
    #used when viewing user profiles
    value = value.replace(value[-5:], value[-5:].replace(".", " [pika] "))
    return value.replace("@", " [afna] ")
    
@register.filter
def profile_link(value):
    #use to automatically create link to user profile
    #example: {{ user.username|profile_link }}
    return '<a href="/portal/profile/%s/">%s</a>' % (value, value)